<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let set1 = new Set(['admin','user1']); // 集合 不能重复
        console.log(set1.size); // 长度
        console.log(set1.has('admin')) // 是否存在某个值
        // console.log(set1.delete('admin'));// delete 删除 返回true | false
        // console.log(set1.values()); // 返回值
        // console.log(set1.clear()); // 清空set
        
        // 将set转为数组
        console.log([...set1]);
        console.log(Array.from(set1));

        let set = new Set('123456789');
        // 返回小于5的值
        let arr = [...set].filter(item=>item<5);
        set = new Set(arr);
        console.log(set); // {"1", "2", "3", "4"}

        let arr1 = [1,2,3,4,5,6,3,5,2];
        let set2 = new Set(arr1); // 使用set去重数组
        console.log(set2)
        console.log(set2.keys())
        console.log(set2.values())
        console.log(set2.entries())
        let set3 = new Set(['admin','usera','userb']);
        set3.forEach(item=>{
            console.log(item);
        })
        for (const key of set3) {
           console.log(key)
        }
    </script>
</body>
</html>